package com.rajesh.messageservice;

import android.os.FileObserver;

public class DatabaseObserver extends FileObserver {
    private static final String TAG = "DatabaseObserver";
    /**
     * 监视文件被修改
     * */
    private Announcer[] announcers = null;
    private String pragmaKey = null;
    private String dbPath = null;

    public DatabaseObserver(String path, String pragmaKey, Announcer... announcers){
        super(path);
        this.dbPath = path;
        this.pragmaKey = pragmaKey;
        this.announcers = announcers;
    }

    @Override
    public void onEvent(int event, String path) {
        switch (event){
            case FileObserver.MODIFY : {
                if(announcers != null){
                    for (Announcer announcer: announcers) {
                        announcer.execute(dbPath, pragmaKey);
                    }
                }
                break;
            }
            default:{
                //do nothing...
                break;
            }
        }
    }
}
